package com.service.role;


import com.entity.Role;
import com.facade.role.IRoleFacadeR;
import com.mapper.CustomMapper;
import com.mapper.RoleMapper;
import com.service.CustomServiceR;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class RoleServiceR extends CustomServiceR<Role> implements IRoleFacadeR {

    @Resource
    private RoleMapper mapper;

    @Override
    protected CustomMapper<Role> initMapper() {
        return mapper;
    }

    @Override
    public List<Role> findByUserLink(Serializable managerId, String... sortOrder) {
        if (null != managerId) {
            Map<String, Object> params = new HashMap<>();
            params.put("managerId", managerId);
            StringBuilder sb0 = new StringBuilder();
            if (null != sortOrder) {
                for (int i = 0; i < sortOrder.length; i++) {
                    sb0.append(sortOrder[i]);
                    if (i != sortOrder.length - 1) {
                        sb0.append(", ");
                    }
                }
            }
            params.put("sortOrder", sb0.toString());
            return mapper.findByUserLink(params);
        }
        return Collections.EMPTY_LIST;
    }
}